﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TA.DotNetUtils
{
	public class FNVHash32 : IHashGenerator<UInt32>, IHashGenerator<Int32>
	{
		#region PUBLIC
		#region METHODS
		public UInt32 Hash(byte[] data)
		{
			return this.Hash(data, FNVHash32.Basis);
		}
		public UInt32 Hash(byte[] data, UInt32 seed)
		{
			UInt32 hash = seed;
			foreach (byte b in data)
			{
				hash *= FNVHash32.Prime;
				hash ^= b;
			}
			return hash;
		}
		int IHashGenerator<int>.Hash(byte[] data)
		{
			return (int)this.Hash(data, (UInt32)FNVHash32.Basis);
		}
		public int Hash(byte[] data, int seed)
		{
			return (int)this.Hash(data, (UInt32)seed);
		}
		#endregion
		#endregion
		#region INTERNAL
		#region CONST/STATIC
		const UInt32 Basis = 2166136261,
			Prime = 16777619;
		#endregion
		#endregion
	}
}
